define(["angularAMD", "moment"], function (angularAMD, moment) {
    angularAMD.service('IIoT0103_Service',
        ['$rootScope', '$filter', '$translate', 'config', 'MMWService', '$mdDialog',
            function ($rootScope, $filter, $translate, config, $MMWService, $mdDialog) {
                this.init = function (options) {
                    var openDialog = function (data) {
                        $mdDialog.dialog(
                            'module/moduleIIoT/program/IIoT01/IIoT0103/IIoT0103.html',
                            function (dialog) {
                                return {
                                    lot_out_data: data.lot_out_data,
                                    css_url: 'module/moduleIIoT/program/IIoT01/IIoT0103/IIoT0103.css',
                                    init: function () {
                                    },
                                    back: function () {
                                        options.feedback(dialog);
                                    },
                                    open_check_out: function (item) {
                                        var machineItem = {};
                                        var plotItem = {};
                                        var type = 'machine'
                                        if (options.parent == 'B0201')
                                            type = 'line'
                                        machineItem.area_no = options.area_no;
                                        machineItem.machine_no = options.equipment_no;
                                        plotItem.plot_no = item.lot_no;
                                        plotItem.open_scan_column = false;
                                        plotItem.op_no = item.op_no;
                                        plotItem.op_plug_in = item.op_plug_in;
                                        plotItem.suggest_qty = item.check_out_qty;
                                        plotItem.need_prod_change = true;

                                        $mdDialog.serviceDialog('B0206Service', machineItem, plotItem, type, 'IIoT0103_Service', function () {
                                            options.feedback(dialog);
                                        });
                                    }
                                }
                            }
                        );
                    }
                    var plot_out_info_get = function () {
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_IIoT.plot_out_info_get',
                            content: {
                                equipment_no: options.equipment_no
                            },
                            success: function (data) {
                                if (data.lot_out_data && data.lot_out_data.length > 0) {
                                    openDialog(data);
                                }
                                else {
                                    $rootScope.showAlert($filter('translate')('IIoT0103.msg.no_lot_out_info'));
                                }
                            }
                        });
                    }
                    plot_out_info_get();
                };
            }]);
});